package proxy.wrappers;

import android.os.Build;
import android.os.IInterface;
import com.genymobile.scrcpy.Ln;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/* loaded from: classes2.dex */
public final class PowerManager {
    private Method isScreenOnMethod;
    private final IInterface manager;

    public PowerManager(IInterface manager) {
        if (manager == null) {
            Ln.w("18 PowerManager is null");
        } else {
            Ln.w("18 PowerManager is not null");
        }
        this.manager = manager;
    }

    private Method getIsScreenOnMethod() throws NoSuchMethodException {
        if (this.isScreenOnMethod == null) {
            String methodName = Build.VERSION.SDK_INT >= 20 ? "isInteractive" : "isScreenOn";
            if (this.manager == null) {
                Ln.w("30 PowerManager is null");
            } else {
                Ln.w("30 PowerManager is not null");
                Class clz = this.manager.getClass();
                StringBuilder sb = new StringBuilder();
                sb.append("clz == null : ");
                sb.append(clz == null);
                Ln.w(sb.toString());
                if (clz != null) {
                    Method method = clz.getMethod(methodName, new Class[0]);
                    StringBuilder sb2 = new StringBuilder();
                    sb2.append("method == null : ");
                    sb2.append(method == null);
                    Ln.w(sb2.toString());
                    if (method != null) {
                        this.isScreenOnMethod = method;
                        return method;
                    }
                }
            }
            this.isScreenOnMethod = this.manager.getClass().getMethod(methodName, new Class[0]);
        }
        return this.isScreenOnMethod;
    }

    public boolean isScreenOn() {
        try {
            Method method = getIsScreenOnMethod();
            return ((Boolean) method.invoke(this.manager, new Object[0])).booleanValue();
        } catch (IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
            Ln.e("Could not invoke method", e);
            return false;
        }
    }
}